package com.jindy.module.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.module.order.domain.OrderProduct;
import com.jindy.module.order.service.IOrderProductService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 订单-产品Controller
 *
 * @author ruoyi
 * @date 2022-10-08
 */
@RestController
@RequestMapping("/module/orderProduct")
public class OrderProductController extends BaseController
{
    @Autowired
    private IOrderProductService orderProductService;

    /**
     * 查询订单-产品列表
     */
//    @PreAuthorize("@ss.hasPermi('module:orderProduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderProduct orderProduct)
    {
        startPage();
        List<OrderProduct> list = orderProductService.selectOrderProductList(orderProduct);
        return getDataTable(list);
    }

    /**
     * 导出订单-产品列表
     */
    @Log(title = "订单-产品", businessType = BusinessType.EXPORT)
//    @PreAuthorize("@ss.hasPermi('module:orderProduct:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderProduct orderProduct)
    {
        List<OrderProduct> list = orderProductService.selectOrderProductList(orderProduct);
        ExcelUtil<OrderProduct> util = new ExcelUtil<OrderProduct>(OrderProduct.class);
        util.exportExcel(response, list, "订单-产品数据");
    }

    /**
     * 获取订单-产品详细信息
     */
//    @PreAuthorize("@ss.hasPermi('module:orderProduct:id')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(orderProductService.selectOrderProductById(id));
    }

    /**
     * 新增订单-产品
     */
    @Log(title = "订单-产品", businessType = BusinessType.INSERT)
//    @PreAuthorize("@ss.hasPermi('module:orderProduct:add')")
    @PostMapping
    public AjaxResult add(@RequestBody OrderProduct orderProduct)
    {
        return toAjax(orderProductService.insertOrderProduct(orderProduct));
    }

    /**
     * 修改订单-产品
     */
    @Log(title = "订单-产品", businessType = BusinessType.UPDATE)
//    @PreAuthorize("@ss.hasPermi('module:orderProduct:update')")
    @PutMapping
    public AjaxResult edit(@RequestBody OrderProduct orderProduct)
    {
        return toAjax(orderProductService.updateOrderProduct(orderProduct));
    }

    /**
     * 删除订单-产品
     */
    @Log(title = "订单-产品", businessType = BusinessType.DELETE)
//    @PreAuthorize("@ss.hasPermi('module:orderProduct:delete')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderProductService.deleteOrderProductByIds(ids));
    }
}
